home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
PROGNG_C
/
CUG187.LZH
/
ZFILL.C
< prev
Wrap
C/C++ Source or Header
|
1985-12-31
|
1KB
|
42 lines
/*@*****************************************************/
/*@ */
/*@ z_fill - zero fill a string in a field of size len */
/*@ The string will be lengthened, if necessary.*/
/*@ */
/*@ Usage: z_fill(str, len); */
/*@ where str is the string area. */
/*@ len is the field size. */
/*@ */
/*@ Returns a pointer to the input string. */
/*@ */
/*@ NOTE: str must be at least len+1 chars long. */
/*@ */
/*@*****************************************************/
char *z_fill(str, size)
char *str;
int size;
{
char *s, *d;
int len, count;
len = strlen(str); /* get string length */
if (len > size) /* truncate, if necessary */
str[size] = 0x00;
else if (len < size) {
d = str + size; /* copy to leave room */
s = str + len;
count = len + 1;
while (count--)
*d-- = *s--;
count = size - len; /* number of zeros to insert */
s = str;
while (count--)
*s++ = '0'; /* add leading zeros */
}
return str;
}